<template>
	<el-form  :model="exitform":rules="rules" ref="exitform" label-width="80px">
	
		<el-form-item label="病人号" prop="patientId">
			<el-select v-model="exitform.patientId" placeholder="请选择">
			    <el-option
			      v-for="item in tableData"
			      :key="item.patientId"
			      :label="item.patientId"
			      :value="item.patientId">
			    </el-option>
			  </el-select>
		</el-form-item>
	
		<el-form-item label="退住类型" prop="exitType">
			
			<el-select v-model="exitform.exitType" placeholder="请选择">
			    <el-option
			      v-for="item in options"
			      :key="item.value"
			      :label="item.lablel"
			      :value="item.value">
			    </el-option>
			  </el-select>
		</el-form-item>
		<el-form-item label="退住原因" prop="exitReason">
			<el-input v-model="exitform.exitReason"></el-input>
		</el-form-item>

		<el-form-item label="申请时间" prop="applyTime">
			<el-date-picker
						      v-model="exitform.applyTime"
						      type="date"
							  value-format="yyyy-MM-dd"
						      placeholder="选择日期">
						    </el-date-picker>
		</el-form-item>

		</el-form-item>
		<el-form-item label="备注">
			<el-input v-model="exitform.remark"></el-input>
		</el-form-item>
		
		
		<el-button type="primary" @click="doExitAdd('exitform')">提交</el-button>
	</el-form>
</template>

<script>
	
	export default{
		name:'ExitAdd',
		props:[
			'dialogVisible'
		],
		data(){
			return {
				tableData:[],
				options: [{
				          value: '正常退住',
				          label: '正常退住'
				        }, {
				          value: '保留床位',
				          label: '保留床位'
				        }, {
				          value: '死亡退住',
				          label: '死亡退住'
				        }],
				exitform:{
					patientId:'',
					exitType:'',
					exitReason:'',
					applyTime:'',
					remarks:''
																		},
				rules: {
			          patientId: [
			            { required: true, message: '请输入客户序号', trigger: 'blur' },
			          ],
			          exitType: [
			            { required: true, message: '请输入退住类型', trigger: 'blur' }
			          ],
					  exitReason: [
					    { required: true, message: '请选择退住原因', trigger: 'change' }
					  ],
					  applyTime: [
					    { required: true, message: '请选择申请时间', trigger: 'change' }
					  ]
					
			        }
			}
		},	
		
		mounted(){
			 this.initPatient();
		},
		methods:{
			doExitAdd(exitform){
				console.log(this.exitform);
				
				this.$refs[exitform].validate((valid) => {
				  if (valid) {	
					  
					this.getRequest("/exit-registrate/insert",this.exitform).then(resp=>{
					if(resp){
						this.$emit("update:dialogVisible",false);
						this.$emit("add")
					}else{
						Message.error({message:'保存失败'});
					}
				})
				
				
				  } else {
				    alert('error submit!!');
				    return false;
				  }
				});
				
			},
			initPatient(){
				this.getRequest('/patient/List').then(resp=>{
					if(resp){         
						this.tableData=resp;
						
					}
				})
			}
		}
	}
</script>

<style>
</style>
